package com.shrcl.engineerprocess.domain.impl;

import com.shrcl.engineerprocess.domain.TSCServiceType;
import com.shrcl.engineerprocess.domain.TSCServiceTypeCategory;
import com.shrcl.engineerprocess.domain.TSCServiceTypeOptionItem;
import com.shrcl.engineerprocess.domain.impl.TSCServiceTypeCategoryImpl;
import com.shrcl.engineerprocess.domain.impl.TSCServiceTypeOptionItemImpl;
import com.shrcl.engineerprocess.domain.proxy.TSCServiceTypeProxy;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("TSCSERVICETYPE_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "tscservicetype")
public class TSCServiceTypeImpl extends BaseModelObject implements TSCServiceType {
  public TSCServiceTypeImpl() {
    super();
  }
  
  @JoinColumn(name = "category_id")
  @ManyToOne(targetEntity = TSCServiceTypeCategoryImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private TSCServiceTypeCategory category;
  
  public TSCServiceTypeCategory getCategory() {
    return this.category;
  }
  
  public TSCServiceType setCategory(final TSCServiceTypeCategory category) {
    this.category = category;
    return this;			
    
  }
  
  private String typeid;
  
  public String getTypeid() {
    return this.typeid;
  }
  
  public TSCServiceType setTypeid(final String typeid) {
    this.typeid = typeid;
    return this;			
    
  }
  
  private String name;
  
  public String getName() {
    return this.name;
  }
  
  public TSCServiceType setName(final String name) {
    this.name = name;
    return this;			
    
  }
  
  @OneToMany(targetEntity = TSCServiceTypeOptionItemImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy = "serviceType")
  private Collection<TSCServiceTypeOptionItem> optionItems = new java.util.ArrayList<com.shrcl.engineerprocess.domain.TSCServiceTypeOptionItem>();;
  
  public Collection<TSCServiceTypeOptionItem> getOptionItems() {
    return this.optionItems;
  }
  
  public TSCServiceTypeOptionItem createAndAddtoOptionItems() {
    getOptionItems().size();
    com.shrcl.engineerprocess.domain.TSCServiceTypeOptionItem tSCServiceTypeOptionItem = new com.shrcl.engineerprocess.domain.impl.TSCServiceTypeOptionItemImpl(this);
    getObjectFactory().create(tSCServiceTypeOptionItem);
    getOptionItems().add(tSCServiceTypeOptionItem);
    return tSCServiceTypeOptionItem;
    
  }
  
  public TSCServiceTypeOptionItem createAndAddtoOptionItems(final Procedure1<TSCServiceTypeOptionItem> updater) {
    getOptionItems().size();
    com.shrcl.engineerprocess.domain.TSCServiceTypeOptionItem tSCServiceTypeOptionItem = new com.shrcl.engineerprocess.domain.impl.TSCServiceTypeOptionItemImpl(this);
    getObjectFactory().create(tSCServiceTypeOptionItem);
    getOptionItems().add(tSCServiceTypeOptionItem);
    return tSCServiceTypeOptionItem;
    
  }
  
  public TSCServiceType removeAllOptionItems() {
    for(TSCServiceTypeOptionItem obj : this.optionItems){
    	getObjectFactory().delete(obj);
    }
    this.optionItems.clear();
    return this;	
    
  }
  
  public TSCServiceType removeFromOptionItems(final TSCServiceTypeOptionItem tSCServiceTypeOptionItem) {
    this.optionItems.remove(tSCServiceTypeOptionItem);
    getObjectFactory().delete(tSCServiceTypeOptionItem);
    return this;
    
  }
  
  public String getEntityName() {
    return this.name;
  }
  
  public static TSCServiceType create(final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.TSCServiceType tSCServiceType = new com.shrcl.engineerprocess.domain.impl.TSCServiceTypeImpl(
    );
    objectFactory.create(tSCServiceType);
    return tSCServiceType;			
    
  }
  
  public static TSCServiceType createTSCServiceTypeImpl(final IObjectFactory objectFactory, final Procedure1<TSCServiceType> init) {
    com.shrcl.engineerprocess.domain.TSCServiceType tSCServiceType = new com.shrcl.engineerprocess.domain.impl.TSCServiceTypeImpl(
    );
    objectFactory.create(tSCServiceType);
    init.apply(tSCServiceType);
    
    return tSCServiceType;			
    
  }
  
  public TSCServiceTypeProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.TSCServiceTypeProxy proxy = new com.shrcl.engineerprocess.domain.proxy.TSCServiceTypeProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
